package com.qidian.mes.sys.controller;

import com.qidian.mes.log.annotation.OptionLogAnnotation;
import com.qidian.mes.log.emum.OptionType;
import com.qidian.mes.pojo.Dict;
import com.qidian.mes.sys.service.DictService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @Time 2023/10/24 14:23
 * @Description
 */
@RestController
@CrossOrigin
@RequestMapping("/dict")
public class DictController {
    @Autowired
    private DictService dictService;

    /**
     * 多条件分页查询字典
     * @param page
     * @param limit
     * @param dict
     * @return
     */
    @GetMapping("/list")
    public MESResult list(@RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10") int limit, Dict dict){
        return dictService.list(page,limit,dict);
    }
    @GetMapping("/get")
    public MESResult get(Long id){
        return dictService.get(id);
    };

    /**
     *新增字典
     * @param dict
     * @return
     */
    @PostMapping("/save")
    @OptionLogAnnotation(optionModule = "sys",optionType = OptionType.INSERT)
    public MESResult save(@RequestBody Dict dict) {
        return dictService.save(dict);
    }

    /**
     * 根据id删除单个字典
     * @param dictId
     * @return
     */
    @DeleteMapping("/delete")
    public MESResult delete(Long dictId){
//        System.out.println("**-*-*-*-*-*-*-*-*-"+dictId);
        return dictService.deleteById(dictId);
    }

    /**
     * 批量删除字典
     * @param dictId
     * @return
     */
    @DeleteMapping("/deletes")
    public MESResult deletes(Long[] dictId){
        return dictService.deletesByDictId(dictId);
    }

    /**
     * 修改字典
     * @param dict
     * @return
     */
    @PutMapping("/update")
    public MESResult update(@RequestBody Dict dict){
//        System.out.println("***-**-*-*-*-*-*"+dict);
        return dictService.update(dict);
    }
    @RequestMapping("/selectById")
    public MESResult selectById(Long dictId){
        return dictService.selectById(dictId);
    }
}
